package object;


import java.util.Stack;

public class Test {
    static class Node{
        public Node next;
        public String val;
        public Node(String val) {
            this.val = val;
            this.next = null;
        }
    }
    public static Node build(){
        Node a = new Node("a");
        Node b = new Node("b");
        Node c = new Node("c");
        Node d = new Node("d");
        a.next = b;
        b.next = c;
        c.next = d;
        d.next = null;
        return a;
    }
//    public static void printList(Node head){
//        if(head == null){
//            return;
//        }
//        printList(head.next);
//        System.out.println(head.val);
//    }
    public static void printList(Node head){
        if(head == null){
            return;
        }
        Stack<String> stack = new Stack<>();
        for(Node cur = head; cur != null; cur = cur.next){
            if(cur != null){
                stack.push(cur.val);
            }
        }
        while(!stack.isEmpty()){
            System.out.println(stack.pop() + "");
        }
    }



    public static void main(String[] args) {
        Node head = build();
        printList(head);
    }
}
